<?php !defined( 'SUNCMS' ) && exit( 'No direct script access allowed'  );

/**
 * 
 * Sun CMS
 * 
 * @author			Burning
 * @copyright		Copyright (c) 2009, IsunCms.Com.
 * @license			http://www.isuncms.com/license.htm
 * @link				http://www.isuncms.com/
 * @since				Version 1.0 Beta
 * 
 */

class Editor{
	
	var $db;
	
	function __construct()
	{
		global $db;
		$this->db = $db;
	}
	
	function save_data( $datas )
	{
		$sql = "SELECT `id` FROM `".DB_PRE."editorcache` ORDER BY `id` DESC LIMIT 0, 10";
		$result = $this->db->query( $sql );
		if( count( $result ) == 10 )
		{
			$end_id = $result[9]['id'];
			$this->db->delete( DB_PRE.'editorcache', array( 'id' => "<= $end_id" ) );
		}
		return $this->db->insert( DB_PRE.'editorcache', array( 'data' => str_replace( '"', "'", escape( $datas ) ), 'time' => TIME ) );
	}
	
	function get_list()
	{
		$sql = "SELECT `id`, `time` FROM `".DB_PRE."editorcache` ORDER BY `id` DESC LIMIT 0, 10";
		$result = $this->db->query( $sql );
		foreach( $result as $k => $v )
		{
			$result[$k]['time'] = date( 'Y-m-d H:i:s', $v['time'] );
		}
		return $result;
	}
	
	function get_data( $id )
	{
		return $this->db->get_one( DB_PRE.'editorcache', array( 'id' => $id ) );
	}
	
}